home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / CALib & You… / Source / CALib / Implementation / UI / CALayout.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-07  |  11.7 KB  |  514 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CALayout.cpp
  3.  
  4.     Contains:    Layout & imaging code for CALib
  5.  
  6.     Written by:    Rick Badertscher, Jens Alfke, Greg Ames, David Nelson
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         
  13.          <15>     11/21/95    RB        Made all acquire operations use temp objects
  14.          <14>     8/2/95        RB        Removed CAGetEmbeddedFrameRef(), Moved CAGetRootFrame()
  15.                                      and CARemoveFrameRef() to CADataX.cpp
  16.          <13>     5/15/95    RB        Adding CAInstallFrameAddedHandler(),
  17.                                      CAInstallFrameAddedHandler(), and
  18.                                      CAInstallEventInEmbeddedHandler(),
  19.          <12>     5/12/95    RB        Fixing bug in CAGetEmbeddedFrame()
  20.                                      Moving all visFrame stuff to CADisplay.cpp
  21.          <11>     4/22/95    RB        Added CARemoveVisFrame()
  22.          <10>     4/19/95    RB        API Renovation.  Transform support.
  23.          <9>     4/07/95    RB        Corrected some ref counting errors.
  24.          <8>     3/30/95    RB        Integrating changes for b1c14 build
  25.          <7>     3/30/95    RB        Mods to CAOffsetFrame().
  26.                                      Added method CAGetEmbeddedFrameRef().  Frame iterator.
  27.          <6>     3/25/95    RB        Implemented CAGetUsedRgn(), CAGetFrameRgn(), CASetFrameRgn(),
  28.                                      and CAGetVisFrame().
  29.          <5>     3/15/95    RB        Added routine CAOffsetFrame(), for scrolling.
  30.          <4+>     2/28/95    SJF        Add debug stuff to API calls
  31.          <4>     2/13/95    SJF        Interim checkin to update project database
  32.          <3)    12/15/94    SJF        change somGetGlobalEnvironment to _gpProxyShell->GetGlobalEnvironment
  33.          <2>    12/15/94    SJF        Move NewShape method to CACommon.cpp
  34.          <1>    10/30/94    GCA,DHN    All mods to make project compile with no
  35.                                      errors under OpenDoc b1 (with SOM).
  36.          <0>    10/30/94    SV        SOMverted
  37.          
  38.     To Do:
  39. */
  40.  
  41. #ifndef _CASESSN_
  42. #include "CASessn.h"
  43. #endif
  44.  
  45. #ifndef _CAERROR_
  46. #include "CAError.h"
  47. #endif
  48.  
  49. #ifndef _CAFRMUTL_
  50. #include "CAFrmUtl.h"
  51. #endif
  52.  
  53. #ifndef _CAUTIL_
  54. #include "CAUtil.h"
  55. #endif
  56.  
  57. #ifndef _CADOCPRIV_
  58. #include "CADocPriv.h"
  59. #endif
  60.  
  61. #ifndef SOM_ODFrame_xh
  62. #include <Frame.xh>
  63. #endif
  64.  
  65. #ifndef SOM_ODFacet_xh
  66. #include <Facet.xh>
  67. #endif
  68.  
  69. #ifndef SOM_ODShape_xh
  70. #include <Shape.xh>
  71. #endif
  72.  
  73. #ifndef SOM_ODTransform_xh
  74. #include <Trnsform.xh>
  75. #endif
  76.  
  77. #ifndef _ODUTILS_
  78. #include <ODUtils.h>
  79. #endif
  80.  
  81. #ifndef SOM_ODWindowState_xh
  82. #include <WinStat.xh>
  83. #endif
  84.  
  85. #ifndef SOM_ODInfo_xh
  86. #include <Info.xh>
  87. #endif
  88.  
  89. #ifndef SOM_ODPart_xh
  90. #include <Part.xh>
  91. #endif
  92.  
  93. #ifndef SOM_ODWindow_xh
  94. #include <Window.xh>
  95. #endif
  96.  
  97. #ifndef _CAPROXYPARTDEF_
  98. #include "CAProxyPartDef.h"
  99. #endif
  100.  
  101. #ifndef CAProxyExtension_API
  102. #include "CAProxyExtension.xh"
  103. #endif
  104.  
  105. #ifndef _CADEBUG_
  106. #include "CADebug.h"
  107. #endif
  108.  
  109. #ifndef SOM_ODFoci_xh
  110. #include <Foci.xh>
  111. #endif
  112.  
  113. #ifndef SOM_ODDraft_xh
  114. #include <Draft.xh>
  115. #endif
  116.  
  117. #ifndef _TEMPOBJ_
  118. #include <TempObj.h>
  119. #endif
  120.  
  121. #ifndef SOM_ODFrameFacetIterator_xh
  122. #include <FrFaItr.xh>
  123. #endif
  124.  
  125.  
  126. #pragma segment CALib
  127.  
  128.  
  129.  
  130. //-------------------------------------------------------------------------
  131. //    Variables 
  132. //-------------------------------------------------------------------------
  133.  
  134.  
  135. //-------------------------------------------------------------------------
  136. //    Layout 
  137. //-------------------------------------------------------------------------
  138.  
  139. //-------------------------------------------------------------------------
  140.  
  141. pascal RgnHandle
  142. CAGetFrameRgn( CADocumentRef document, CAFrameRef frame )
  143. {
  144.     
  145. #ifdef RUNTIME_DEBUG
  146.     VALIDATE_DOCREF ("CAGetFrameRgn", document);
  147.     VALIDATE_FRAMEREF ("CAGetFrameRgn", document, frame);
  148. #endif
  149.  
  150.     Environment*    ev        = gCASession->GetEV();
  151.     ODRgnHandle        rgn        = kODNULL;
  152.     
  153.     if (FailIfNotVisible(document)) return NULL;
  154.     
  155.     CA_TRY
  156.     
  157.         TempODFrame tempFrame = AcquireFrameFromFrameRef (document, frame);
  158.         TempODShape tempShape = tempFrame->AcquireFrameShape (ev, kODNULL);
  159.         rgn = tempShape->CopyQDRegion (ev);
  160.         
  161.     CA_CATCH_ALL
  162.     CA_ENDTRY
  163.     
  164.     return rgn;
  165.     
  166.     // Caller is responsible for usedRgn memory
  167.     
  168. }
  169.  
  170.  
  171. //-------------------------------------------------------------------------
  172.  
  173. pascal void
  174. CASetFrameRgn( CADocumentRef document, CAFrameRef frame,
  175.                 RgnHandle frameRgn )
  176. {
  177.  
  178. #ifdef RUNTIME_DEBUG
  179.     VALIDATE_DOCREF ("CASetFrameRgn", document);
  180.     VALIDATE_FRAMEREF ("CASetFrameRgn", document, frame);
  181. #endif
  182.  
  183.     Environment*        ev        = gCASession->GetEV();
  184.  
  185.     if (FailIfNotVisible(document)) return;
  186.  
  187.     CA_TRY
  188.     
  189.         TempODFrame tempFrame = AcquireFrameFromFrameRef (document,frame);
  190.         tempFrame->Invalidate (ev, kODNULL, kODNULL);
  191.         
  192.         TempODShape tempShape = tempFrame->CreateShape (ev);
  193.         tempShape->SetQDRegion (ev, frameRgn);
  194.         tempFrame->ChangeFrameShape(ev, tempShape, kODNULL);        // GCA HACK added kODNULL (ODCanvas) 10/30/94
  195.  
  196.     CA_CATCH_ALL
  197.     CA_ENDTRY
  198.  
  199. }
  200.  
  201.  
  202.  
  203. //-------------------------------------------------------------------------
  204.  
  205. pascal RgnHandle
  206. CAGetUsedRgn( CADocumentRef document, CAFrameRef frame )
  207. {
  208.  
  209. #ifdef RUNTIME_DEBUG
  210.     VALIDATE_DOCREF ("CAGetUsedRgn", document);
  211.     VALIDATE_FRAMEREF ("CAGetUsedRgn", document, frame);
  212. #endif
  213.  
  214.     Environment*    ev            = gCASession->GetEV();
  215.     RgnHandle        usedRgn        = kODNULL;
  216.     
  217.     if (FailIfNotVisible(document)) return NULL;
  218.  
  219.     CA_TRY
  220.     
  221.         TempODFrame tempFrame = AcquireFrameFromFrameRef (document, frame);
  222.     
  223.         if (tempFrame->IsRoot (ev))
  224.         {
  225.             ODPoint        point;
  226.             Point        contentExtent, contentTransformPoint;
  227.             ODFacet*    facet;
  228.             
  229.             TempODWindow tempWindow =  tempFrame->AcquireWindow(ev);
  230.             facet = tempWindow->GetRootFacet(ev);
  231.     
  232.             tempFrame->GetContentExtent (ev, &point);
  233.             contentExtent = point.AsQDPoint();
  234.         
  235.             TempODTransform tempTransform = facet->AcquireContentTransform (ev, kODNULL);
  236.             contentTransformPoint = tempTransform->GetQDOffset (ev);
  237.         }
  238.     
  239.         TempODShape tempUsedShape = tempFrame->AcquireUsedShape (ev, kODNULL);
  240.         usedRgn = tempUsedShape->CopyQDRegion (ev);
  241.     
  242.     CA_CATCH_ALL
  243.     CA_ENDTRY
  244.     
  245.     return (usedRgn);
  246.     
  247.     // Caller is responsible for usedRgn memory
  248.     
  249. }
  250.  
  251.  
  252.  
  253. //-------------------------------------------------------------------------
  254.  
  255. pascal Boolean
  256. CAGetFrozen( CADocumentRef document, CAFrameRef frame )
  257. {
  258.  
  259.     Environment*    ev = gCASession->GetEV();
  260.     Boolean            retVal = kODFalse;
  261.     
  262.     CA_TRY
  263.     
  264.         TempODFrame tempFrame = AcquireFrameFromFrameRef(document, frame);
  265.         retVal = tempFrame->IsFrozen(ev);
  266.         
  267.     CA_CATCH_ALL
  268.     CA_ENDTRY
  269.     
  270.     return (retVal);
  271.     
  272. }
  273.  
  274.  
  275. //-------------------------------------------------------------------------
  276.  
  277. pascal void
  278. CASetFrozen( CADocumentRef document, CAFrameRef frame, Boolean isFrozen )
  279. {
  280.     Environment*        ev = gCASession->GetEV();
  281.  
  282.     CA_TRY
  283.     
  284.         TempODFrame tempFrame = AcquireFrameFromFrameRef(document, frame);
  285.         tempFrame->SetFrozen(ev, isFrozen);
  286.         
  287.     CA_CATCH_ALL
  288.     CA_ENDTRY
  289.     
  290. }
  291.  
  292. //-------------------------------------------------------------------------
  293.  
  294. pascal void    CAGetFrameTransform (    CADocumentRef    document,
  295.                                     CAFrameRef        frameRef,
  296.                                     CATransform*    transform)
  297. {
  298.     Environment*        ev = gCASession->GetEV();
  299.  
  300.     CA_TRY
  301.     
  302.         TempODFrame tempFrame = AcquireFrameFromFrameRef (document, frameRef);
  303.         
  304.         // Get the internal transform of the frame
  305.     
  306.         TempODTransform tempTransform = tempFrame->AcquireInternalTransform (ev, kODNULL);
  307.         THROW_IF_NULL (tempTransform);
  308.         tempTransform->GetMatrix(ev, (ODMatrix*) transform);
  309.  
  310.     CA_CATCH_ALL
  311.     CA_ENDTRY
  312.     
  313.  
  314. }
  315.  
  316. //-------------------------------------------------------------------------
  317.  
  318. pascal    void CASetFrameTransform(    CADocumentRef    document,
  319.                                      CAFrameRef        frameRef,
  320.                                     CATransform*    transform)
  321. {
  322.  
  323.     Environment*        ev            = gCASession->GetEV();
  324.  
  325.     CA_TRY
  326.     
  327.         TempODFrame tempFrame = AcquireFrameFromFrameRef (document, frameRef);
  328.         THROW_IF_NULL (tempFrame);
  329.     
  330.         // By default the external transform is identity
  331.         TempODTransform tempTransform = tempFrame->CreateTransform(ev);
  332.         THROW_IF_NULL (tempTransform);
  333.     
  334.         tempTransform->SetMatrix (ev, (ODMatrix*) transform);
  335.         tempFrame->ChangeInternalTransform (ev, tempTransform, kODNULL);
  336.         
  337.         //tempFrame->Invalidate (ev, kODNULL, kODNULL);
  338.  
  339.         
  340.     CA_CATCH_ALL
  341.     CA_ENDTRY
  342.     
  343.     return;
  344.  
  345. }
  346.  
  347. //-------------------------------------------------------------------------
  348.  
  349. pascal Boolean CAShowPartFrameInfo(CADocumentRef document, CAVisFrame visFrame)
  350. {
  351.  
  352.     Environment*        ev        = gCASession->GetEV();
  353.     ODInfo*                info;
  354.     ODDraft*            draft    = kODNULL;
  355.     ODDraftPermissions    perms;
  356.  
  357.  
  358.     CA_TRY
  359.     
  360.         info = gCASession->GetODSession()->GetInfo(ev);
  361.         THROW_IF_NULL (info);
  362.         
  363.         draft = ((CADocument*)document)->GetDraft();
  364.         perms = draft->GetPermissions(ev);
  365.     
  366.         info->ShowPartFrameInfo( ev, (ODFacet*)visFrame, perms >= kODDPSharedWrite);
  367.  
  368.     CA_CATCH_ALL
  369.     CA_ENDTRY
  370.     
  371.     return (true);
  372.  
  373. }
  374.  
  375. //-------------------------------------------------------------------------
  376.  
  377. pascal void CAViewFrameInWindow (CADocumentRef document, CAFrameRef frame)
  378. {
  379.  
  380.     Environment*        ev        = gCASession->GetEV();
  381.     
  382.     CA_TRY
  383.     
  384.         TempODFrame tempFrame = AcquireFrameFromFrameRef (document, frame);
  385.         TempODPart tempPart = tempFrame->AcquirePart (ev);
  386.         tempPart->Open(ev, tempFrame);
  387.  
  388.     CA_CATCH_ALL
  389.     CA_ENDTRY
  390.  
  391. }
  392.  
  393. //-------------------------------------------------------------------------
  394.  
  395. pascal Boolean CAActiveBorderContainsPoint (Point mouse)
  396. {
  397.     
  398.     Environment*        ev                        = gCASession->GetEV();
  399.     ODWindowState*        windowState                = gCASession->GetODSession()->GetWindowState(ev);
  400.     ODArbitrator*        arbitrator                = gCASession->GetArbitrator();
  401.     Boolean                cursorInActiveBorder    = false;
  402.     ODFacet*            rootFacet;
  403.     ODPoint                odPoint;
  404.     ODPoint                windowMouse;
  405.     
  406.     odPoint = mouse;
  407.     
  408.     CA_TRY
  409.     
  410.         TempODWindow tempWindow = windowState->AcquireActiveWindow (ev);
  411.         
  412.         if (tempWindow)
  413.         {
  414.             // Get the root facet
  415.             rootFacet = tempWindow->GetRootFacet (ev);
  416.         
  417.             // get the active frame
  418.             TempODFrame tempFrame = arbitrator->AcquireFocusOwner(ev, gCASession->GetODSession()->Tokenize(ev, kODSelectionFocus));
  419.     
  420.             if (tempFrame && !tempFrame->IsRoot(ev))
  421.             {
  422.         
  423.                 ODFrameFacetIterator*    iter = tempFrame->CreateFacetIterator(ev);
  424.                 ODPoint                    windowPoint;
  425.                 
  426.                 TempODTransform windowFrameXForm = rootFacet->AcquireWindowFrameTransform(ev, kODNULL);
  427.                 windowPoint = odPoint;
  428.                 windowFrameXForm->TransformPoint(ev, &windowPoint);
  429.  
  430.                 // For each facet, check if the active border contains the mouse
  431.                 for (ODFacet* facet = iter->First(ev); iter->IsNotComplete(ev);
  432.                     facet = iter->Next(ev))
  433.                 {
  434.                     TempODTransform xForm = facet->AcquireWindowFrameTransform(ev, kODNULL);
  435.                     ODPoint         framePoint;
  436.                     
  437.                     framePoint = windowPoint;
  438.                     xForm->InvertPoint(ev, &framePoint);
  439.                     
  440.                     if (facet->ActiveBorderContainsPoint(ev, &framePoint, kODNULL))
  441.                     {
  442.                         cursorInActiveBorder = true;
  443.                         break;
  444.                     } 
  445.                 }
  446.                 ODDeleteObject(iter);
  447.             }
  448.         }
  449.         
  450.     CA_CATCH_ALL
  451.     CA_ENDTRY
  452.  
  453.     return (cursorInActiveBorder);
  454.  
  455. }
  456.  
  457.  
  458.  
  459. //-------------------------------------------------------------------------
  460. pascal    void        CAInstallFrameShapeRequestHandler (    CAFrameShapeRequestHandler handler,
  461.                                                         CADocumentRef    document)
  462. {
  463.     Environment*        ev = gCASession->GetEV();
  464.     ODPart*                rootPart = kODNULL;
  465.     CAProxyExtension*    proxyExt = kODNULL;
  466.  
  467.  
  468.     CA_TRY
  469.     
  470.         rootPart = ((CADocument*)document)->AcquireRootPart();
  471.         proxyExt = (CAProxyExtension*)rootPart->AcquireExtension( ev, kCAProxyPartExtension );
  472.     
  473.         THROW_IF_NULL (proxyExt);
  474.  
  475.         proxyExt->InstallCAFrameShapeRequestHandler( ev,
  476.                 (CAProxyHookFrameShapeRequest) ProxyHook_FrameShapeRequest, handler);
  477.  
  478.     CA_CATCH_ALL
  479.     CA_ENDTRY
  480.     
  481.     ODReleaseObject (ev, proxyExt);
  482.     ODReleaseObject (ev, rootPart);
  483.  
  484. }
  485.                                                     
  486. //-------------------------------------------------------------------------
  487.  
  488.  
  489. pascal    void        CAInstallBorderAdjuster(CADocumentRef document,
  490.                                              CAAdjustBorderProc theProc)
  491. {
  492.     Environment*        ev = gCASession->GetEV();
  493.     ODWindowState*        windowState = gCASession->GetODSession()->GetWindowState(ev);
  494.     ODPart*                rootPart = kODNULL;
  495.     CAProxyExtension*    proxyExt = kODNULL;
  496.  
  497.  
  498.     CA_TRY
  499.     
  500.         rootPart = ((CADocument*)document)->AcquireRootPart();
  501.         proxyExt = (CAProxyExtension*)rootPart->AcquireExtension( ev, kCAProxyPartExtension );
  502.     
  503.         THROW_IF_NULL (proxyExt);
  504.  
  505.         proxyExt->InstallCAAdjustBorderHandler( ev,
  506.                 (CAProxyHookAdjustBorder) ProxyHook_AdjustBorder, theProc);
  507.  
  508.     CA_CATCH_ALL
  509.     CA_ENDTRY
  510.     
  511.     ODReleaseObject (ev, proxyExt);
  512.     ODReleaseObject (ev, rootPart);
  513.  
  514. }